/*
 * @Author: 
 * @Date: 2025-09-16 16:10:41
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2025-09-16 16:14:52
 * @Description: 
 */
import {
    Controller,
    Get,
    Post,
    Body,
    Patch,
    Param,
    Delete,
    ParseIntPipe,
  } from '@nestjs/common';
  import {
    ApiTags,
    ApiOperation,
    ApiResponse,
    ApiParam,
  } from '@nestjs/swagger';
  import { UsersService } from './users.service';
  import { CreateUserDto } from './dto/create-user.dto';
  import { UpdateUserDto } from './dto/update-user.dto';
  import { UserResponseDto } from './dto/user-response.dto';
  
  @ApiTags('用户管理')
  @Controller('users')
  export class UsersController {
    constructor(private readonly usersService: UsersService) {}
  
    @Post()
    @ApiOperation({ summary: '创建用户' })
    @ApiResponse({
      status: 201,
      description: '用户创建成功',
      type: UserResponseDto,
    })
    @ApiResponse({ status: 409, description: '用户名或邮箱已存在' })
    create(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
      return this.usersService.create(createUserDto);
    }
  
    @Get()
    @ApiOperation({ summary: '获取所有用户' })
    @ApiResponse({
      status: 200,
      description: '成功获取用户列表',
      type: [UserResponseDto],
    })
    findAll(): Promise<UserResponseDto[]> {
      return this.usersService.findAll();
    }
  
    @Get(':id')
    @ApiOperation({ summary: '根据ID获取用户' })
    @ApiParam({ name: 'id', description: '用户ID' })
    @ApiResponse({
      status: 200,
      description: '成功获取用户信息',
      type: UserResponseDto,
    })
    @ApiResponse({ status: 404, description: '用户不存在' })
    findOne(@Param('id', ParseIntPipe) id: number): Promise<UserResponseDto> {
      return this.usersService.findOne(id);
    }
  
    @Delete(':id')
    @ApiOperation({ summary: '删除用户' })
    @ApiParam({ name: 'id', description: '用户ID' })
    @ApiResponse({ status: 200, description: '用户删除成功' })
    @ApiResponse({ status: 404, description: '用户不存在' })
    remove(@Param('id', ParseIntPipe) id: number): Promise<void> {
      return this.usersService.remove(id);
    }
  }